/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.bank;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.bank.BankCardBin;
import com.server.modules.sys.service.bank.BankCardBinService;

/**
 * 卡Bin管理Controller
 * @author 王磊
 * @version 2016-11-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/bank/bankCardBin")
public class BankCardBinController extends BaseController {


	@Autowired
	private BankCardBinService bankCardBinService;
	
	@ModelAttribute
	public BankCardBin get(@RequestParam(required=false) String id) {
		BankCardBin entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bankCardBinService.get(id);
		}
		if (entity == null){
			entity = new BankCardBin();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:bank:bankCardBin:view")
	@RequestMapping(value = {"list", ""})
	public String list(BankCardBin bankCardBin, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BankCardBin> page = bankCardBinService.findPage(new Page<BankCardBin>(request, response), bankCardBin); 
		model.addAttribute("page", page);
		model.addAttribute("bankCardBin", bankCardBin);
		return "modules/sys/bank/bankCardBinList";
	}

	@RequiresPermissions("sys:bank:bankCardBin:view")
	@RequestMapping(value = "form")
	public String form(BankCardBin bankCardBin, Model model) {
		model.addAttribute("bankCardBin", bankCardBin);
		return "modules/sys/bank/bankCardBinForm";
	}

	@RequiresPermissions("sys:bank:bankCardBin:edit")
	@RequestMapping(value = "save")
	public String save(BankCardBin bankCardBin, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bankCardBin)){
			return form(bankCardBin, model);
		}
		bankCardBinService.save(bankCardBin);
		addMessage(redirectAttributes, "保存卡Bin成功");
		return "redirect:"+Global.getAdminPath()+"/sys/bank/bankCardBin/?repage";
	}
	
	@RequiresPermissions("sys:bank:bankCardBin:edit")
	@RequestMapping(value = "delete")
	public String delete(BankCardBin bankCardBin, RedirectAttributes redirectAttributes) {
		bankCardBinService.delete(bankCardBin);
		addMessage(redirectAttributes, "删除卡Bin成功");
		return "redirect:"+Global.getAdminPath()+"/sys/bank/bankCardBin/?repage";
	}

}